package com.zhiyou.aifeng.smart_machine

import android.os.Bundle
import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.entity.LocalMedia
import com.zhiyou.aifeng.common.base.oneClick
import com.zhiyou.aifeng.common.helper.get
import com.zhiyou.aifeng.common.helper.getString
import com.zhiyou.aifeng.common_ui.base.BaseActivity
import com.zhiyou.aifeng.common_ui.base.loadImage
import com.zhiyou.aifeng.common_ui.oss.scaleMImage
import com.zhiyou.aifeng.utils.GlideEngine
import com.zhiyou.aifeng.viewmodel.RealViewModel
import kotlinx.android.synthetic.main.activity_real_info.*

class RealInfoActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_real_info)
        initTitle(title = "我的认证", divider = false)
    }

    override fun getViewModel() = get<RealViewModel>()

    override fun initTitle(title: String, name: String, divider: Boolean) {
        super.initTitle(title, name, divider)
        real_name.setRightString(getString("realName"))
        real_num.setRightString(getString("idCard"))
        real_tel.setRightString(getString("phone"))
        real_area.setRightString(getString("authRegion"))
        real_detail.setRightString(getString("authAdress"))

        real_img1.loadImage(getString("authGroup").scaleMImage(pxSize = 300))
        real_img2.loadImage(getString("authFront").scaleMImage(pxSize = 300))
        real_img3.loadImage(getString("authBack").scaleMImage(pxSize = 300))

        real_img1.oneClick { openPreview(0) }
        real_img2.oneClick { openPreview(1) }
        real_img3.oneClick { openPreview(2) }
    }

    private fun openPreview(position: Int) {
        PictureSelector.create(this)
            .themeStyle(R.style.Picture_Green_Style)
            .imageEngine(GlideEngine.createGlideEngine())
            .isNotPreviewDownload(false)
            .openExternalPreview(
                position,
                arrayListOf(
                    LocalMedia().apply { path = getString("authGroup") },
                    LocalMedia().apply { path = getString("authFront") },
                    LocalMedia().apply { path = getString("authBack") }
                )
            )
    }

}